package com.tanhua.controller;

import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.SettingsVo;
import com.tanhua.server.SettingsSever;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author 杰哥不要啦~
 * @date 2021/10/28
 */
@RestController
@RequestMapping("/user")
public class SettingsController {
    private SettingsSever settingsSever;

    @GetMapping("/setting")
    public ResponseEntity setting(){
       SettingsVo vo = settingsSever.setting();
       return ResponseEntity.ok(vo);
    }

    /**
     * 设置陌生人问题
     */
    @PostMapping("/questions")
    public ResponseEntity questions(@RequestBody Map map){
        //获取参数
        String content = (String) map.get("content");
        settingsSever.saveQuestion(content);
        return ResponseEntity.ok(null);
    }
    /**
     * 通知设置
     */
    @PostMapping("/notifications/setting")
    public ResponseEntity notifications(@RequestBody Map map){
        settingsSever.saveSettings(map);
        return ResponseEntity.ok(null);
    }
    /**
     * 黑名单
     */
    @GetMapping("/blacklist")
    public ResponseEntity blacklist(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "1") int size
    ){
        //1、调用service查询
        PageResult pr = settingsSever.blacklist(page,size);
        //2、构造返回
        return ResponseEntity.ok(pr);
    }
    /**
     * 取消黑名单
     *

     *
     *
     */
    @DeleteMapping("/blacklist/{uid}")
    public ResponseEntity deleteBlackList(@PathVariable("uid") Long blackUserId) {
        settingsSever.deleteBlackList(blackUserId);
        return ResponseEntity.ok(null);
    }
}
